//
//  HWAssetsTopCell.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/1/27.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWAssetsTopCell: UITableViewCell {
    
    var bgView:UIView!
    /// 推广公告图标
    var promoteNoticeImageView:UIImageView!
    /// 推广公告
    var promoteNoticeLabel:UILabel!
    var promoteNoticeButton:UIButton!
    /// 推广二维码
    var promoteQRCodeImageView:UIImageView!
    /// 推广二维码
    var promoteQRCodeLabel:UILabel!
    var promoteQRCodeButton:UIButton!
    /// 分成明细图标
    var divideDetailImageView:UIImageView!
    /// 分成明细
    var divideDetailLabel:UILabel!
    var divideDetailButton:UIButton!
    
    var promoteNoticeButtonClick:(()->())?
    var promoteQRCodeButtonClick:(()->())?
    var divideDetailButtonClick:(()->())?
    
    class func cellWithTableView(tableView:UITableView) -> (HWAssetsTopCell) {
        let reUse:String = "HWAssetsTopCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWAssetsTopCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWAssetsTopCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        bgView = UIView()
        bgView.backgroundColor = .white
        bgView.layer.cornerRadius = 12*widthScale
        contentView.addSubview(bgView)
        
        promoteNoticeImageView = UIImageView()
        promoteNoticeImageView.image = UIImage(named: "promoteNotice")
        bgView.addSubview(promoteNoticeImageView)
        
        promoteNoticeLabel = HWLabel.createBoldLabel(title: "推广公告", color: "#333333", font: 14*widthScale)
        bgView.addSubview(promoteNoticeLabel)
        
        promoteNoticeButton = UIButton(type: .custom)
        promoteNoticeButton.addTarget(self, action: #selector(promoteNoticeButtonClick(_:)), for: .touchUpInside)
        bgView.addSubview(promoteNoticeButton)
        
        promoteQRCodeImageView = UIImageView()
        promoteQRCodeImageView.image = UIImage(named: "promoteQRCode")
        bgView.addSubview(promoteQRCodeImageView)
        
        promoteQRCodeLabel = HWLabel.createBoldLabel(title: "分享二维码", color: "#333333", font: 14*widthScale)
        bgView.addSubview(promoteQRCodeLabel)
        
        promoteQRCodeButton = UIButton(type: .custom)
        promoteQRCodeButton.addTarget(self, action: #selector(promoteQRCodeButtonClick(_:)), for: .touchUpInside)
        bgView.addSubview(promoteQRCodeButton)
        
        divideDetailImageView = UIImageView()
        divideDetailImageView.image = UIImage(named: "divideDetail")
        bgView.addSubview(divideDetailImageView)
        
        divideDetailLabel = HWLabel.createBoldLabel(title: "分成明细", color: "#333333", font: 14*widthScale)
        bgView.addSubview(divideDetailLabel)
        
        divideDetailButton = UIButton(type: .custom)
        divideDetailButton.addTarget(self, action: #selector(divideDetailButtonClick(_:)), for: .touchUpInside)
        bgView.addSubview(divideDetailButton)
    }
    
    func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.left.equalTo(20*widthScale)
            make.right.equalTo(-20*widthScale)
            make.top.equalTo(10*widthScale)
            make.bottom.equalTo(-10*widthScale)
            make.height.equalTo(100*widthScale)
        }
        
        promoteNoticeImageView.snp.makeConstraints { make in
            make.left.equalTo(39*widthScale)
            make.top.equalTo(20*widthScale)
            make.width.height.equalTo(34*widthScale)
        }
        
        promoteNoticeLabel.snp.makeConstraints { make in
            make.centerX.equalTo(promoteNoticeImageView)
            make.top.equalTo(promoteNoticeImageView.snp.bottom).offset(9*widthScale)
        }
        
        promoteNoticeButton.snp.makeConstraints { make in
            make.left.right.bottom.equalTo(promoteNoticeLabel)
            make.top.equalTo(promoteNoticeImageView)
        }
        
        promoteQRCodeImageView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalTo(promoteNoticeImageView)
            make.width.height.equalTo(34*widthScale)
        }
        
        promoteQRCodeLabel.snp.makeConstraints { make in
            make.centerX.equalTo(promoteQRCodeImageView)
            make.top.equalTo(promoteQRCodeImageView.snp.bottom).offset(9*widthScale)
        }
        
        promoteQRCodeButton.snp.makeConstraints { make in
            make.left.right.bottom.equalTo(promoteQRCodeLabel)
            make.top.equalTo(promoteQRCodeImageView)
        }
        
        divideDetailImageView.snp.makeConstraints { make in
            make.right.equalTo(-38*widthScale)
            make.centerY.equalTo(promoteNoticeImageView)
            make.width.height.equalTo(34*widthScale)
        }
        
        divideDetailLabel.snp.makeConstraints { make in
            make.centerX.equalTo(divideDetailImageView)
            make.top.equalTo(divideDetailImageView.snp.bottom).offset(9*widthScale)
        }
        
        divideDetailButton.snp.makeConstraints { make in
            make.left.right.bottom.equalTo(divideDetailLabel)
            make.top.equalTo(divideDetailImageView)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

extension HWAssetsTopCell {
    @objc func promoteNoticeButtonClick(_ button:UIButton) -> Void {
        self.promoteNoticeButtonClick?()
    }
    
    @objc func promoteQRCodeButtonClick(_ button:UIButton) -> Void {
        self.promoteQRCodeButtonClick?()
    }
    
    @objc func divideDetailButtonClick(_ button:UIButton) -> Void {
        self.divideDetailButtonClick?()
    }
}
